var layer = layui.layer //弹层
    ,table = layui.table //表格
    ,form = layui.form,$ = layui.jquery,laydate = layui.laydate;
layui.use(['tableEdit',"excel"], function () {
    let tableEdit = layui.tableEdit;
    let layer = layui.layer,
        excel = layui.excel;

    lay('.starttime').each(function () {
        laydate.render({
            elem: this
        });
    });

    layer.ready(function () {
        //供应商
        $.ajax({
            url: "customer2/getAllInspectUnit",
            success: function (res) {
                if (res.status == 200) {
                    $.each(res.data, function (index, item) {
                        $("#supplierCode").append(new Option(item.name, item.code));
                    });
                    form.render('select');
                } else {
                    layer.msg(res.msg, {icon: 5});
                }
            }
        });
    });
    form.render();//表单刷新

    let initData = [];
    table.render({
        elem: '#statisticsSelect'
        , data: initData
        , url: 'productmaininfo/statistics/productPriceDetailStatisticsListByPage'
        , toolbar: '#statisticsToolbar'
        , cols: [[
              {field: 'numbers',width: 50,type:'numbers',title:'序号'}
            , {field:'supplierName',  title: '供应商名称',width: 300, align: 'center'}
            , {field: 'productCode', title: '产品编码',width: 220, align: 'center'}
            , {field: 'specificationCode', title: '规格编码',width: 300, align: 'center'}
            , {field: 'taxIncludedCost', title:'含税出厂价',sort:true,width: 220, align: 'center'}
            , {field: 'untaxedCost', title: '未税出厂价', sort: true,width: 220, align: 'center'}
            , {field:'fob', title:'含税FOB价', sort: true,width: 220, align: 'center'}
            , {field:'cshh', title:'未含税FOB价', sort: true,width: 220, align: 'center'}
            , {field:'currencyName', title:'币种',width: 220, align: 'center'}
            , {field: 'createDateStr', title: '创建日期', sort: true,width: 220, align: 'center'}
            , {field: 'updateDateStr', title: '修改日期', sort: true,width: 220, align: 'center'}
        ]]
        , id: 'statisticsTableId'
        , height: $(document).height() - $('#statisticsSelect').offset().top - 50
        , page: true
        , limit: 300
        , limits: [300, 600, 900]
    });

    form.on('submit(submitform)', function (data) {
        table.reload('statisticsTableId', {
            page: {
                limit:300,
                curr: 1
            }
            , where: data.field
        }, 'data');
        return false;
    });

    form.on('submit(exportData)', function (queryReq) {
        let index = layer.load(2, {
            shade: [0.4, '#000'],
            content: '加载中...',
            success: function (layero) {
                layero.find('.layui-layer-content').css({
                    'padding-top': '40px',
                    'width': '200px'
                });
            }
        });
        $.ajax({
            data: queryReq.field,
            url:"productmaininfo/productPriceDetailStatisticsExport",
            success: function(res) {
                if(res.status == 200){
                    //配置列宽
                    let colConf = excel.makeColConfig({
                        'A': 150,
                        'X': 150
                    }, 80);
                    excel.exportExcel({
                        sheet1: res.data.data
                    }, '厂商产品排价.xlsx', 'xlsx', {
                        extend: {
                            '!cols': colConf
                        }
                    });
                }else {
                    layer.msg(res.msg, {icon: 5});
                }
                layer.close(index);
                return false;
            }
        });
        return false;
    });

});